/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.ext.DialectSyntaxParser;
import net.iwsh.core.db.ext.SQLWithParams;
import net.iwsh.core.utils.IDGenerator;

import com.us.usws.model.domain.video.VideoExtattr;
import com.us.usws.model.flat.video.DOVideoExtattr;

/**
 * DAO class
 * @author robot
 */
public class VideoExtattrDAO {

	/**
	 * Query SQLs
	 */
	private static final String SQL_GET_TOTAL_COUNT = "select count(*) from hv_video_extattr";

	private static final String SQL_GET_ALL_VIDEOEXTATTRS = "select * from hv_video_extattr";

	private static final String SQL_GET_VIDEOEXTATTR_BY_PK = "select * from hv_video_extattr where uid = ?";

	private static final String SQL_GET_EXT_ATTR_BY_VIDEO = "select * from hv_video_extattr where video_uid=?";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_VIDEOEXTATTR = "insert into hv_video_extattr(uid,video_uid,extattr_uid,value,seq_num,create_by_uid,create_date,last_upd_by_uid,last_upd_date) values (?,?,?,?,?,?,?,?,?)";

	private static final String SQL_UPDATE_VIDEOEXTATTR = "update hv_video_extattr set video_uid=?, extattr_uid=?, value=?, seq_num=?, create_by_uid=?, create_date=?, last_upd_by_uid=?, last_upd_date=? where uid=?";

	private static final String SQL_DEL_VIDEOEXTATTR = "delete from hv_video_extattr where uid=?";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get Count.
	 */
	public int getTotalCount() {
		return dbe.getCount(SQL_GET_TOTAL_COUNT);
	}

	/**
	 * Get all list.
	 */
	public List<VideoExtattr> getAllVideoExtattrs() {
		return dbe.list(SQL_GET_ALL_VIDEOEXTATTRS, VideoExtattr.class);
	}

	/**
	 * Get all list by pagination.
	 */
	public List<VideoExtattr> getVideoExtattrs(int start, int end) {
		SQLWithParams swp = DialectSyntaxParser.getParser().getPaginationSQLWithParams(SQL_GET_ALL_VIDEOEXTATTRS, null, start, end);
		return dbe.list(swp.getSql(), VideoExtattr.class, swp.getParams());
	}

	/**
	 * Get VideoExtattr by primary key.
	 */
	public VideoExtattr getVideoExtattr(String uid) {
		VideoExtattr v = dbe.load(SQL_GET_VIDEOEXTATTR_BY_PK, VideoExtattr.class, uid);
		return v;
	}

	/**
	 * load by video uid
	 * @param videoUid
	 * @return
	 */
	public List<VideoExtattr> getVideoExtattByVideoUid(String videoUid) {
		return dbe.list(SQL_GET_EXT_ATTR_BY_VIDEO, VideoExtattr.class, videoUid);
	}

	/**
	 * Insert one row.
	 */
	public String insertVideoExtattr(DOVideoExtattr videoExtattr) {
		String uid = IDGenerator.getInstance().genUID();
		videoExtattr.setUid(uid);
		dbe.execute(SQL_INSERT_VIDEOEXTATTR, videoExtattr.getUid(), videoExtattr.getVideoUid(), videoExtattr.getExtattrUid(),
				videoExtattr.getValue(), videoExtattr.getSeqNum(), videoExtattr.getCreateByUid(), videoExtattr.getCreateDate(),
				videoExtattr.getLastUpdByUid(), videoExtattr.getLastUpdDate());
		return uid;
	}

	/**
	 * Update by PK.
	 */
	public void updateVideoExtattr(DOVideoExtattr videoExtattr) {
		dbe.execute(SQL_UPDATE_VIDEOEXTATTR, videoExtattr.getVideoUid(), videoExtattr.getExtattrUid(), videoExtattr.getValue(),
				videoExtattr.getSeqNum(), videoExtattr.getCreateByUid(), videoExtattr.getCreateDate(), videoExtattr.getLastUpdByUid(),
				videoExtattr.getLastUpdDate(), videoExtattr.getUid());
	}

	/**
	 * Delete row by PK.
	 */
	public void deleteVideoExtattr(String uid) {
		dbe.execute(SQL_DEL_VIDEOEXTATTR, uid);
	}

}